<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>客户组详情管理</title>
	<meta name="decorator" content="default"/>
</head>
<body>
	<form:form id="searchForm" modelAttribute="customerGroupDetail" action="${ctx}/base/customerGroupDetail/list" method="post">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="groupId" name="groupId" type="hidden" value="${groupId}"/>
		<div class="icon-buttons">
			<a href="${ctx}/base/customerGroup/"  data-icon="back" data-iconpos="notext"  data-role="button" data-inline="true">返回</a>
		</div>
		<div class="middleCls">
			<input type="button" value="成员添加"  data-icon="plus" data-inline="true" onclick="selectCustomers()">
			<c:if test="${not empty page.list}">
				<input type="button" value="删除全部"  data-icon="delete" data-inline="true" onclick="deleteAllCustomers('${groupId}')">
			</c:if>
		</div>
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
		<thead><tr><th>姓名</th><th>年龄</th><th>体重</th><th>电话</th><th>婚姻状况</th><th>操作</th></tr></thead>
		<tbody>
		<c:if test="${empty page.list}">
			<tr>
				<td colspan="6">此群没有成员</td>
			</tr>
		</c:if>
		<c:if test="${not empty page.list}">
			<c:forEach items="${page.list}" var="customerGroupDetail">
				<tr id="${customerGroupDetail.customer.id}" class="selectCls">
					<td>${customerGroupDetail.customer.name}</td>
					<td>${fns:getAge(customerGroupDetail.customer.birthday)}</td>
					<td>${customerGroupDetail.customer.weight} KG</td>
					<td>${customerGroupDetail.customer.mobile}</td>
					<td>${fns:getDictLabel(customerGroupDetail.customer.marry, 'marry', '')}</td>
					<td>
						<a data-role="button"  data-icon="delete" data-iconpos="notext"  data-inline="true" onclick="bossLoginDeletePopup('确定将此客户移出客户群？', '${ctx}/base/customerGroupDetail/delete?groupId=${customerGroupDetail.customerGroup.id}&customerId=${customerGroupDetail.customer.id}')">移出此群</a>
					</td>
				</tr>
			</c:forEach>
		</c:if>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	<script type="text/javascript">
		$(document).ready(function() {
			getSelectedCustomer();
		});	
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
			return false;
        }
		var ids; 
		function getSelectedCustomer(){
			ids = ''; 
			var tr = $(".selectCls");
			if (tr && tr.length > 0) {
				for(var i = 0, len = tr.length; i < len; i ++){
					var c = tr[i];
	        		ids +=  c.id + ',';
				}
			}
		}
		function selectCustomers(){
			var fun = function(){
				var addIds = "";
				var items = $('#dialog-mult-select ul li input');
				for(var i=0; i<items.length; i++) {
					var item = $(items[i]);
					if(item.prop("checked") == true) {
						var id = item.attr("id");
						addIds += id + ",";
					};
				}
				var url = "${ctx}/base/customerGroupDetail/save?groupId=${groupId}&customerIds=" + addIds;
				window.location.href = url;
			};
			getSelectedCustomer();
			global.multSelectDialog("${ctx}/base/customer/customerData", "选择客户", ids ,fun);
		}
		function deleteAllCustomers(gid){
			var url = "${ctx}/base/customerGroupDetail/delete?groupId="+gid+"&customerId=0";
			bossLoginDeletePopup("确定移除客户群的所有成员？", url);
		}
	</script>
</body>
</html>
